load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin
  fils = systemfunc("ls "+"data/ts_signal_noise_5yr_h*.nc"); noise derived from single-forcing simulations
  fs   = addfiles(fils,"r")
  ListSetType(fs,"cat")
  resi = fs[:]->resi 

  fread = addfile("data/ts_noise_5yr_piControl.nc","r"); noise derived from piControl
  pi    = fread->noise 

  n1 = dimsizes(resi)
  n2 = dimsizes(pi)

  noise = new((/n1(0)+n2(0),14/),"float") 
  noise(:n1(0)-1,:) = resi 
  noise(n1(0):,:)   = pi 

  noise = noise-conform(noise,dim_avg_n_Wrap(noise,1),0)

  noise!0 = "member"
  noise&member = ispan(0,n1(0)+n2(0)-1,1)
  noise!1 = "time"
  noise&time = ispan(0,13,1)

  printVarSummary(noise)

  filo = "data/ts_all_noise_samples.asc"; internal variability covariances, which will be divided further
  asciiwrite(filo,ndtooned(noise))
end 